package com.linwen.excise.od;

import java.util.Scanner;

/**
 * @ClassName _三叉树的高度
 * @Description TODO
 * @Author zero
 * @DATE 2024/4/10 10:39 PM
 * @Version 1.0
 */
public class _三叉树的高度 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if(n==0){
            System.out.println(0);
            return;
        }
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        Node root = new Node(arr[0]);
        for (int i = 1; i < n; i++) {
            buildTree(root,arr[i]);
        }
        System.out.println(findDepth(root));
    }

    private static int findDepth(Node root) {
        return dfs(root,0);
    }

    private static int dfs(Node root, int i) {
        if(root==null){
            return 0;
        }
        if(root.left==null&&root.mid==null&&root.right==null){
            return i+1;
        }
        return Math.max(dfs(root.left,i+1),Math.max(dfs(root.mid,i+1),dfs(root.right,i+1)));
    }

    private static void buildTree(Node root, int data) {
        Node node = new Node(data);
        if(root.value>data+500){
            if(root.left!=null){
                buildTree(root.left,data);
            }else {
                root.left = new Node(data);
            }
        }else if(root.value+500<data){
            if(root.right!=null){
                buildTree(root.right,data);
            }else {
                root.right = new Node(data);
            }
        }else {
            if(root.mid!=null){
                buildTree(root.mid,data);
            }else {
                root.mid = new Node(data);
            }
        }
    }

}

class Node{
    int value;
    Node left;
    Node mid;
    Node right;
    Node(int value){
        this.value = value;
    }
}
